#!/usr/bin/ruby
# -*- ruby -*-

require 'set'

dict = Set.new

File.open(File.basename(__FILE__).
    gsub('-easy.rb', '-all.input')).
    readlines.
    each { |w| dict << w.strip }

ARGV.each do |word|
    next_steps = Set.new

    (0 .. word.size - 1).each do |i|
        prefix = i == 0 ? "" : word[0 .. i - 1]
        suffix = word[i + 1, word.size]

        ('a' .. 'z').each do |ch|
            w = prefix + ch + suffix

            next_steps << w if dict.include?(w) && w != word
        end
    end

    puts next_steps.to_a.sort.join(" ")
end
